package com.exam.controller;

import com.exam.pojo.*;
import com.exam.service.AdminService;
import com.exam.service.StudentService;
import com.exam.service.TeacherService;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private AdminService adminService;
    @PostMapping("/login")
    public ApiResult login(@RequestBody Login login){
        Student student=studentService.getStudent(login);
        Teacher teacher=teacherService.getTeacher(login);
        Admin admin=adminService.getAdmin(login);
        if (student!=null)return ApiResultHandler.buildApiResult(200,"请求成功",student);
        if (teacher!=null)return ApiResultHandler.buildApiResult(200,"请求成功",teacher);
        if (admin!=null)return ApiResultHandler.buildApiResult(200,"请求成功",admin);
        return ApiResultHandler.buildApiResult(400,"请求失败",null);
    }

}
